package com.gongjian.web.controller;

import com.gongjian.database.entity.User;
import com.gongjian.database.service.UserService;
import com.gongjian.utile.CodeEntity;
import com.gongjian.utile.Ids;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: TanLiLin
 * @Date: 2019/3/22 10:49
 * @Version 1.0
 */
@RestController
public class Usercontroller {
    @Autowired
    UserService userService;

//添加

    /**
     * 添加学生
     * @param user
     * @return
     */
   @RequestMapping("user/addStuUser")
   public String addStuUser(@RequestBody User user){
       return userService.addStuUser(user);
   }

    /**
     * 添加老师
     * @param user
     * @return
     */
    @RequestMapping("user/addTeaUser")
    public String addTeaUser(@RequestBody User user){
        return userService.addTeaUser(user);
    }


// 删除

    /**
     * 多条记录删除
     * @param ids
     * @return
     */
    @RequestMapping("/user/deleteUser")
    public String deleteUser(@RequestBody Ids ids){
        return userService.deleteUser(ids.getIds());
    }


 //    修改

    /**
     * 通过用户id修改用户
     * @param user
     * @return
     */
    @RequestMapping("/user/updateUser")
    public String updateUser(@RequestBody User user) {
        return userService.updateUser(user);
    }


    /**
     * 根据用户id修改用户type
     * @param user
     * @return
     */
    @RequestMapping("/user/updateUserTypeByUserId")
    public String updateUserTypeByUserId(@RequestBody User user) {
        return userService.updateUserTypeByUserId(user);
    }


    //   查询

    /**
     * 查询所有学生
     * @return
     */
    @RequestMapping("/user/findAllUserByStu")
    public  String  findAllUserByStu(int Page,int PageSize) {
        return userService.findAllUserByStu(Page,PageSize);
    }

    /**
     * 查询所有教师
     * @param Page
     * @param PageSize
     * @return
     */
    @RequestMapping("/user/findAllUserByTea")
    public  String  findAllUserByTea(int Page,int PageSize) {
        return userService.findAllUserByTea(Page,PageSize);
    }


    @RequestMapping("/user/findAllUserByTeaNoPage")
    public  String  findAllUserByTea() {
        return userService.findAllUserByTeaNoPage();
    }

    @RequestMapping("/user/findAllUserByFudaoyuanNoPage")
    public  String  findAllUserByFudaoyuan() {
        return userService.findAllUserByFudaoyuanNoPage();
    }


    /**
     * 查询一个学生
     * @param userId
     * @return
     */
    @RequestMapping("/user/findOneUserByStuUserId")
    public String findOneUserByStuUserId(int userId) {
        return userService.findOneUserByStuUserId(userId);
    }

    /**
     * 查询一个教师
     * @param userId
     * @return
     */
    @RequestMapping("/user/findOneUserByTeaUserId")
    public String findOneUserByTeaUserId(int userId){
        return userService.findOneUserByTeaUserId(userId);
    }

    /**
     * 根据usertype查询一条记录
     * @param userType
     * @return
     */
    @RequestMapping("/user/findOneUserByUserType")
    public String findOneUserByUserType(int userType){
        return userService.findOneUserByUserType(userType);
    }


    /**
     * 根据userNumber 或 userName查询学生
     * @param Page
     * @param PageSize
     * @param userNumber
     * @param userName
     * @param userType
     * @return
     */
    @RequestMapping("/user/search")
    public String searchUser(int Page,int PageSize,String userNumber,String userName,int userType){
        User user = new User();
        user.setUserName(userName);
        user.setUserNumber(userNumber);
        user.setUserType(userType);
        return userService.searchUser(Page,PageSize,user);
    }


}
